unit product;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dbbase, StdCtrls, Buttons, Mask, RzEdit, RzRadChk, RzButton,
  Grids, DBGrids, RzDBGrid, ExtCtrls, DB;

type
  Tproductfrm = class(TdbbaseFrm)
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure IniParam;override;
    procedure QFindRcd;override;
    procedure PrintRpt;override;
    procedure FindRcd;override;
    procedure AddRcd;override;
    procedure EditRcd;override;
    procedure DelRcd;override;
    procedure CutCnnt;override;
    procedure FrmExit;override;
  end;

var
  productfrm: Tproductfrm;

implementation

{$R *.dfm}

uses includefile, editprdct, dbmodule;

Procedure Tproductfrm.IniParam;
var
  i:integer;
begin 
  for i:=0 to 3 do begin
    dbgrid.Columns[i].Title.Caption:=GetCaption('productfrm',5001+i);
  end;
  DataSource.DataSet:=dbmodulefrm.dbquery;
  with dbmodulefrm.dbquery  do begin
    active:=False;
    sql.Clear;
    sql.add('select * from product');
    execsql;
    active:=True;
    for i:=0 to 3 do begin
      dbgrid.Columns[i].FieldName:=Fields[i].FieldName;
    end;
  end;
end;

procedure Tproductfrm.QFindRcd;
var
  tmp:string;
begin
  tmp:=Trim(edit_qsearch.Text);
  with DBGrid.DataSource.DataSet do begin
    Active:=False;
    Filter:=Format('PRONAME like ''*%s*'' or PROALIAS like ''*%s*'' or PROREMARK like ''*%s*''',
                   [tmp,tmp,tmp]);
    Filtered:=True;
    Active:=True;
  end;
end;

procedure Tproductfrm.PrintRpt;
begin

end;

procedure Tproductfrm.FindRcd;
begin

end;

procedure Tproductfrm.AddRcd;
var
  prc:real;
  index:integer;
begin
  with Teditprdctfrm.Create(Application) do begin
    caption:=GetCaption('editprdctfrm',1000);
    if mrok=showmodal then begin
      val(txtPrice.Text,prc,index);
      dbmodulefrm.dbquery.Active:=False;
      dbmodulefrm.dbquery.SQL.Clear;
      dbmodulefrm.dbquery.SQL.Add('insert into PRODUCT ');
      dbmodulefrm.dbquery.sql.Add('(PRONAME,PROALIAS,PROPRICE,PROREMARK) ');
      dbmodulefrm.dbquery.sql.Add(Format('VALUES (''%s'',''%s'',%f,''%s'')',
                        [txtId.Text,txtName.Text,txtAlias.Text,prc,txtRemark.Text]));
      dbmodulefrm.dbquery.ExecSQL;
      iniParam;
    end;
  end;
end;

procedure Tproductfrm.EditRcd;
var
  PRONAME:string;
  prc:real;
  index:integer;
begin
  with Teditprdctfrm.Create(Application) do begin
    caption:=GetCaption('editprdctfrm',999);
    //txtId.Text:=dbgrid.DataSource.DataSet.fieldbyname('PRONAME').AsString;
    //PRONAME:=txtId.Text;
    txtName.Text:=dbgrid.DataSource.DataSet.fieldbyname('PRONAME').AsString;
    PRONAME:=txtName.Text;
    txtAlias.Text:=dbgrid.DataSource.DataSet.fieldbyname('PROALIAS').AsString;
    txtPrice.Text:=dbgrid.DataSource.DataSet.fieldbyname('PROPRICE').AsString;
    txtRemark.Text:=dbgrid.DataSource.DataSet.fieldbyname('PROREMARK').AsString ;
    if mrok=showmodal then begin
      val(txtPrice.Text,prc,index);
      dbmodulefrm.dbquery.Active:=False;
      dbmodulefrm.dbquery.SQL.Clear;
      dbmodulefrm.dbquery.SQL.Add('Update PRODUCT ');
      dbmodulefrm.dbquery.sql.Add(
        Format('SET PRONAME=''%s'',PROALIAS=''%s'',PROPRICE=%f,PROREMARK=''%s''',
        [txtName.Text,txtAlias.Text,prc,txtRemark.Text]));
      dbmodulefrm.dbquery.sql.Add(Format(' Where PRONAME=''%s''',[PRONAME]));
      dbmodulefrm.dbquery.ExecSQL;
      iniParam;
    end;
  end;
end;

procedure Tproductfrm.DelRcd;
var
  tmp:string;
begin
  if IDYES=Application.MessageBox(pchar(GetCaption('Msgbox',105)),
                                  pchar(GetCaption('Msgbox',104)),MB_YESNO) then begin
    tmp:=dbgrid.DataSource.DataSet['PRONAME'];
    with dbmodulefrm.dbquery  do begin
      active:=False;
      sql.Clear;
      sql.Add(Format('Delete from product where PRONAME=''%s''',[tmp]));
      execsql;
    end;
    IniParam;
  end;
end;

procedure Tproductfrm.CutCnnt;
begin

end;

procedure Tproductfrm.FrmExit;
begin
  dbmodulefrm.dbquery.Active:=False;
  Hide;
end;

end.
